﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using TCS.Model;
namespace TCS.BLL
{
    /// <summary>
    /// 业务逻辑类Gsp_Administrative 的摘要说明。
    /// </summary>
    public class Gsp_Administrative
    {
        private readonly TCS.DAL.Gsp_Administrative dal = new TCS.DAL.Gsp_Administrative();
        public Gsp_Administrative()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int AddID)
        {
            return dal.Exists(AddID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(TCS.Model.Gsp_Administrative model)
        {
            dal.Add(model);
        }
        public void Add(string AddName, string Remark, int ParentID, string Temp, string Depth)
        {
            dal.AddNew(AddName,Remark,ParentID,Temp,Depth);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(TCS.Model.Gsp_Administrative model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int AddID)
        {

            dal.Delete(AddID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TCS.Model.Gsp_Administrative GetModel(int AddID)
        {

            return dal.GetModel(AddID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public TCS.Model.Gsp_Administrative GetModelByCache(int AddID)
        {

            string CacheKey = "Gsp_AdministrativeModel-" + AddID;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(AddID);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (TCS.Model.Gsp_Administrative)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        public DataSet GetListNew(int Top, string strWhere, string filedOrder)
        {
            return dal.GetListNew(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TCS.Model.Gsp_Administrative> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TCS.Model.Gsp_Administrative> DataTableToList(DataTable dt)
        {
            List<TCS.Model.Gsp_Administrative> modelList = new List<TCS.Model.Gsp_Administrative>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                TCS.Model.Gsp_Administrative model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new TCS.Model.Gsp_Administrative();
                    if (dt.Rows[n]["AddID"].ToString() != "")
                    {
                        model.AddID = int.Parse(dt.Rows[n]["AddID"].ToString());
                    }
                    model.AddName = dt.Rows[n]["AddName"].ToString();
                    model.Remark = dt.Rows[n]["Remark"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

